package com.example.mifi;

import java.util.HashMap;
import java.util.List;
import java.util.Vector;

import android.graphics.PointF;
import android.net.wifi.ScanResult;

public class Geopoint extends PointF
{
	private Vector<Geopoint> mNeighbours;
	private HashMap<String, Integer> mVals;
	private HashMap<String, Integer> mPosVals; //galimos reiksmes
	private long mLastDistance;
	
	public Geopoint()
	{
		super();
		init();
	}

	public Geopoint(float x, float y)
	{
		super(x, y);
		init();
	}

	private void init()
	{
		mNeighbours = new Vector<Geopoint>();
		mVals = new HashMap<String, Integer>();
		mPosVals = new HashMap<String, Integer>();
	}
	
	public void addNeighbour(Geopoint gp)
	{
		mNeighbours.add(gp);
	}

	public void addValue(String mac, int value)
	{
		mVals.put(mac, value);
	}
	
	public void addPossibleValue(String mac, int value)
	{
		mPosVals.put(mac, value);
	}

	public long getDistance(List<ScanResult> list)
	{
		long dist = 0;
		long countContains = 0;
		for (ScanResult sr : list)
		{
			if (mVals.containsKey(sr.BSSID))
			{
				if (mVals.get(sr.BSSID) != 0)
				{
					countContains++;
					long d = Math.abs(Math.abs(sr.level) - Math.abs(mVals.get(sr.BSSID)));
					if (d > 5)
						dist += d * d * d;
				}
				/*else
					dist += 50;*/
			}
			/*else if (mPosVals.containsKey(sr.BSSID) && (mPosVals.get(sr.BSSID) != 0) )
			{
				dist += Math.abs(Math.abs(sr.level) - Math.abs(mPosVals.get(sr.BSSID)));
			}*/
		}
		dist += (sizeNonZero() - countContains) * 100;
		
		mLastDistance = dist;
		return dist;
	}

	private long sizeNonZero()
	{
		int count = 0;
		for (int v : mVals.values())
		{
			if (v != 0)
				count++;
		}
		return count;
	}

	public long getLastDistance()
	{
		return mLastDistance;
	}
	
}
